/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.edu.ufg.notasWebApp;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author javaee
 */
public class procesarNotas extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Calculo del promedio</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Binevenido al programa: Promedio de Asignaturas</h1>");
            
            String asig1 = request.getParameter("asig1");
            String asig2 = request.getParameter("asig2");
            String asig3 = request.getParameter("asig3");
            String asig4 = request.getParameter("asig4");
            String asig5 = request.getParameter("asig5");
            String asig6 = request.getParameter("asig6");
            
            int mat1 = Integer.parseInt(request.getParameter("mat1"));
            int mat2 = Integer.parseInt(request.getParameter("mat2"));
            int mat3 = Integer.parseInt(request.getParameter("mat3"));
            int mat4 = Integer.parseInt(request.getParameter("mat4"));
            int mat5 = Integer.parseInt(request.getParameter("mat5"));
            int mat6 = Integer.parseInt(request.getParameter("mat6"));
            
            double promedio =(mat1+mat2+mat3+mat4+mat5+mat6)/6;
            out.println("<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\" style=\"border-collapse:collapse;\">");
            out.println("<tr><td>Asignatura</td><td>Nota</td></tr>");
            out.println("<tr><td>"+asig1+"</td><td>"+mat1+"</td></tr>");
            out.println("<tr><td>"+asig2+"</td><td>"+mat2+"</td></tr>");
            out.println("<tr><td>"+asig3+"</td><td>"+mat3+"</td></tr>");
            out.println("<tr><td>"+asig4+"</td><td>"+mat4+"</td></tr>");
            out.println("<tr><td>"+asig5+"</td><td>"+mat5+"</td></tr>");
            out.println("<tr><td>"+asig6+"</td><td>"+mat6+"</td></tr>");
            out.println("<tr><td>Promedio</td><td>"+promedio+"</td></tr>");
            out.println("</table>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
